package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAccountTraceMapper;
import com.qf.pojo.DtsAccountTrace;
import com.qf.pojo.DtsUser;
import com.qf.pojo.DtsUserAccount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class DtsAccountTraceServiceImpl implements DtsAccountTraceService {
    @Autowired
    private DtsAccountTraceMapper dtsAccountTraceMapper;
    //佣金总数
    @Override
    public int count() {
        Integer total = dtsAccountTraceMapper.selectCount(null);

        return total;
    }

    @Override
    public List<DtsAccountTrace> find(int page, int limit, String sort, String order,int... statusArray) {

        QueryWrapper<DtsAccountTrace> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderBy(!StringUtils.isEmpty(sort),"asc".equalsIgnoreCase(order),sort);
        //模糊查询用户名,手机号--排序方式
        queryWrapper.in(!StringUtils.isEmpty(statusArray),"status",statusArray);


        //自定义分页对象
        IPage<DtsAccountTrace> dtsAccountIPage =
                dtsAccountTraceMapper.selectPage(new Page<DtsAccountTrace>(page,limit),queryWrapper);

        List<DtsAccountTrace> dtsAccountTracesList = dtsAccountIPage.getRecords();
        return dtsAccountTracesList;



    }
    //佣金审批
    @Override
    public void approve(int id, int status, String traceMsg) {
        //1.通过id 获得佣金对象
        DtsAccountTrace dtsAccountTrace = dtsAccountTraceMapper.selectOne(new LambdaQueryWrapper<DtsAccountTrace>()
                .eq(DtsAccountTrace::getId,id));
        //修改状态  1或者2
        dtsAccountTrace.setStatus(status);
        //修改备注
        dtsAccountTrace.setTraceMsg(traceMsg);
        //修改
        dtsAccountTraceMapper.updateById(dtsAccountTrace);

    }
}
